//
//  VISTASettingMenu.m
//  VISTA看天下
//
//  Created by 邱海龙 on 15/12/6.
//  Copyright © 2015年 邱海龙. All rights reserved.
//

#import "VISTASettingMenu.h"

@implementation VISTASettingMenu

- (instancetype)initWithFrame:(CGRect)frame
{
    if (self = [super initWithFrame:frame]) {
        _titleArray = @[@"文章字号",@"收藏列表",@"分享设置",@"用户登录",@"推送设置",@"用户反馈",@"关于我们",@"应用程序推荐",@"清除缓存",];
        NSArray *imageArray = @[@"文章字号.png",@"收藏夹.png",@"分享设置.png",@"用户登录.png",@"推送通知.png",@"应用程序推荐.png",@"关于我们.png",@"应用程序推荐.png",@"清除缓存.png"];
        self.btnArray = [NSMutableArray array];
        
        
        [self.layer setCornerRadius:6];
        [self.layer setBorderWidth:1];
        [self.layer setBorderColor:[UIColor colorWithRed:0.8 green:0.8 blue:0.8 alpha:0.8].CGColor];
       
        for (int i = 0; i < _titleArray.count; i ++) {
            UIImageView *imageView = [[UIImageView alloc]initWithFrame:CGRectMake(5, 5+40*i, 30, 30)];
            [imageView setImage:[UIImage imageNamed:imageArray[i]]];
            [self addSubview:imageView];

            UILabel *label = [[UILabel alloc]initWithFrame:CGRectMake(45, 5+40*i, 100, 30)];
            [label setText:_titleArray[i]];
            label.textColor = [UIColor grayColor];
            label.font = [UIFont systemFontOfSize:13];
            [self addSubview:label];
            
            if (i != 4 && i!=8) {
                UIImageView *sjImgView = [[UIImageView alloc]initWithFrame:CGRectMake(frame.size.width-30, 12+40*i, 15, 15)];
                [sjImgView setImage:[UIImage imageNamed:@"三角.png" ]];
                [self addSubview:sjImgView];
            }else{
                self.switchImageView = [[UIImageView alloc]initWithFrame:CGRectMake(frame.size.width -  76, 7+40*4, 61, 25)];
                [self.switchImageView setImage:[UIImage imageNamed:@"开.png"]];
                [self addSubview:self.switchImageView];
                
                self.fontLabel = [[UILabel alloc]initWithFrame:CGRectMake(frame.size.width-60, 12, 15, 15)];
                [self.fontLabel setText:@"中"];
                self.fontLabel.textColor = [UIColor grayColor];
                self.fontLabel.font = [UIFont systemFontOfSize:13];
                [self addSubview:self.fontLabel];
                
            }
            
            if (i) {
                UIView *line = [[UIView alloc]initWithFrame:CGRectMake(0, 40*i, frame.size.width, 1)];
                [line setBackgroundColor:[UIColor colorWithRed:0.8 green:0.8 blue:0.8 alpha:0.8]];
                [self addSubview:line];
            }
           
            UIButton *button = [UIButton buttonWithType:UIButtonTypeSystem];
            button.frame = CGRectMake(0, 40*i, frame.size.width, 40);
    
            [button setBackgroundImage:[UIImage imageNamed:@"ad_title_bg.png"] forState:UIControlStateHighlighted];
            [button addTarget:self action:@selector(click:) forControlEvents:UIControlEventTouchUpInside];
            [self addSubview:button];
            [self.btnArray addObject:button];
            
        }
    }
    return  self;
}
- (void)click:(id)sender
{
    UIButton *button = (UIButton *)sender;
    NSInteger index = [self.btnArray indexOfObject:button];
    if ([self.delegate respondsToSelector:@selector(settingBar:didClickButton:WithButtonIndex:)]) {
        [self.delegate settingBar:self didClickButton:button WithButtonIndex:index];
    }
}

@end
